define(function (require) {
    var _common = require('common/main');
    var _config = require('common/config');
    var _send = _common.sendRequest;
    function init() {
    	$('#order_query').click(_query_order);
    	$('#order_download').click(_download_order);
    	var _param = {};
    	_send("food/listFood.ajax",_param,_list_food_render);
    	_send("zone/listPlace.ajax",_param,_list_place_render);
    }
    
    function _download_order()
	{
		var _userid = $('#order_userid').val();
		var _zoneid = $('#order-pickplace option:selected').attr("value");
		var _payway = $('#order-payway option:selected').attr("value");
		var _drinkfoodid = $('#order-drink option:selected').attr("value");
		var _pickdateF = $('#order_pickdateF').val();
		var _pickdateT = $('#order_pickdateT').val();
		var _mainfoodid = $('#order-food option:selected').attr("value");
		var _state = $('#order-state option:selected').attr("value");
		alert("blah");
		window.location.href="tool/download_orders.do?drinkfoodid="+_drinkfoodid+"&mainfoodid="+_mainfoodid+"&payway="+_payway+"&pickdateF="+_pickdateF+"&pickdateT="+_pickdateT+"&state="+_state+"&userid="+_userid+"&zoneid="+_zoneid;
		alert("blah2");
	}
    
    function _query_order()
	{
		var _userid = $('#order_userid').val();
		var _zoneid = $('#order-pickplace option:selected').attr("value");
		var _payway = $('#order-payway option:selected').attr("value");
		var _drinkfoodid = $('#order-drink option:selected').attr("value");
		var _pickdateF = $('#order_pickdateF').val();
		var _pickdateT = $('#order_pickdateT').val();
		var _mainfoodid = $('#order-food option:selected').attr("value");
		var _state = $('#order-state option:selected').attr("value");

		var _param = _common.stringify({
			userid : _userid,
			zoneid : _zoneid,
			payway : _payway,
			drinkfoodid : _drinkfoodid,
			mainfoodid : _mainfoodid,
			pickdateF : _pickdateF,
			pickdateT : _pickdateT,
			state : _state
		});
		_send("order/queryOrder.ajax", _param, _query_order_render);
	}
    
    function _query_order_render(data) {
		var _len = data.length;
		$('#order_search').html('<span style="color:red"><font><b>共有'+_len+'条搜索结果</b></font></span><br/>');
		var _html = '';
		for (var i = 0; i < _len; i++) {
			var _item = data[i];
			_html += '<tr class="success">';
			_html += '<td width="9%">';
			_html += _item.id;
			_html += '</td>';
			
			_html += '<td width="9%">';
			_html += _item.userid;
			_html += '</td>';
			
			_html += '<td width="8%">';
			_html += _item.username;
			_html += '</td>';
			
			_html += '<td width="9%">';
			_html += _item.pickname;
			_html += '</td>';
			
			_html += '<td width="7%">';
			_html += _item.priceStr;
			_html += '</td>';
			
			_html += '<td width="8%">';
			_html += _item.mainfood;
			_html += '</td>';
			
			_html += '<td width="8%">';
			_html += _item.drinkfood;
			_html += '</td>';
			
			_html += '<td width="9%">';
			_html += _item.payway;
			_html += '</td>';
			
			_html += '<td width="9%">';
			_html += _item.state;
			_html += '</td>';
			
			_html += '<td width="8%">';
			_html += _item.bookdate;
			_html += '</td>';
			
			_html += '<td width="8%">';
			_html += _item.orderdate;
			_html += '</td>';
			
			_html += '<td width="8%">';
			_html += _item.pickdate;
			_html += '</td>';
			
			_html += '</tr>';
		}
		
		$('#order_list').html(_html);
	}
    
    function _list_place_render(data)
    {
    	var _html = '<option value="-1">全部</option>';
    	var _len = data.length;
    	for (var i = 0; i < _len; i++) 
    	{
			var _item = data[i];
			_html += '<option value="';
			_html += _item.id;
			_html += '">';
			_html += _item.pickName;
			_html += '</option>';
    	}
    	$('#order-pickplace').html(_html);
    }
    
    function _list_food_render(data)
    {
    	var _mainhtml = '<option value="-1">全部</option>';
    	var _drinkhtml = '<option value="-1">全部</option>';
    	var _len = data.length;
    	for (var i = 0; i < _len; i++) 
    	{
			var _item = data[i];
			
			if(_item.type==1)
			{
				_mainhtml += '<option value="';
				_mainhtml += _item.id;
				_mainhtml += '">';
				_mainhtml += _item.name;
				_mainhtml += '</option>';
			}
			if(_item.type==2)
			{
				_drinkhtml += '<option value="';
				_drinkhtml += _item.id;
				_drinkhtml += '">';
				_drinkhtml += _item.name;
				_drinkhtml += '</option>';
			}
    	}
    	$('#order-drink').html(_drinkhtml);
    	$('#order-food').html(_mainhtml);
    }
    
    return { init: init };
});